"use strict";
/* Controllers */
app.controller("yarnQuotaAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'yarnQuotaAddService', function ($scope, $location, $rootScope, $routeParams, yarnQuotaAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    var errorFn = function (result) {
        alert(result);
    };

    $scope.setYarnQuota = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id,
            clusterName: vm.p.clusterName,
            queueType: vm.p.queueType,
            queue: vm.p.queue,
            queueDesc: vm.p.queueDesc,
            cpuMin: vm.p.cpuMin,
            cpuMax: vm.p.cpuMax,
            memMin: vm.p.memMin,
            memMax: vm.p.memMax,
            ownerID: vm.p.ownerID,
            ownerCn: vm.p.ownerCn,
            departID: vm.p.departID
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //window.location = "#/star/yarnQuota/yarnQuota_list";
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        yarnQuotaAddService.setYarnQuota(params, procFn, errorFn);
    };
    $scope.getYarnQuota = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //vm.p = JSON.stringify(response.data);
                vm.p = response.data;
            } else {
                alert(response.msg);
            }
        };
        yarnQuotaAddService.getYarnQuota(params, procFn, errorFn);
    };

    //
    if(vm.p.id!=0) {
        $scope.getYarnQuota();
    }
}]);


/* Services */
app.service('yarnQuotaAddService', ['ajaxService', function (ajaxService) {

    this.setYarnQuota = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_quota/setYarnQuota.do", successFunction, errorFunction);
    };
    this.getYarnQuota = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_quota/getYarnQuota.do", successFunction, errorFunction);
    };
}]);

